package com.tanhua.app.controller;

import com.tanhua.app.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
public class CommentController {

    @Autowired
    private CommentService commentService;

    @GetMapping(value = "/comments", name = "评论列表")
    public ResponseEntity findCommentVoByPage(
            @RequestParam(name = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(name = "pagesize", defaultValue = "10") Integer pageSize,
            @RequestParam(name = "movementId") String publishId) {
        return commentService.findCommentVoByPage(pageNum, pageSize, publishId);
    }

    @PostMapping(value = "/comments", name = "动态评论")
    public ResponseEntity publishComment(@RequestBody Map<String, String> param) {
        String publishId = param.get("movementId");
        String text = param.get("comment");

        return commentService.publishComment(publishId,text);
    }
}
